package com.uuah.server.config.spring.factories;

import com.uuah.config.i18n.MessageFactory;
import com.uuah.server.api.endpoint.IEndpointFactory;
import com.uuah.server.api.endpoint.IUuahEndpoint;
import com.uuah.server.exception.config.ConfigurationException;

/**
 * Spring FactoryBean used to create concrete instances of uuah endpoints
 */
public class UuahEndpointFactoryBean extends AbstractEndpointFactoryBean {

	public UuahEndpointFactoryBean() {
		super();
	}

	public Class getObjectType() {
		return IUuahEndpoint.class;
	}

	public Object doGetObject() throws Exception {
		IEndpointFactory ef = uuahContext.getRegistry().lookupEndpointFactory();
		if (ef != null) {
			return ef.getRequestEndpoint(this);
		} else {
			throw new ConfigurationException(
					MessageFactory
							.createStaticMessage("EndpointFactory not found in Registry"));
		}
	}

}
